package com.top.ruizhong.main.host

import android.app.Activity
import android.content.Intent
import android.view.Gravity
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import com.blankj.utilcode.util.ColorUtils
import com.google.android.material.tabs.TabLayout
import com.module.lemlin.base.BaseAbstractActivity
import com.top.ruizhong.R
import kotlinx.android.synthetic.main.activity_settlement_order.*

class SettlementOrderActivity : BaseAbstractActivity() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, SettlementOrderActivity::class.java)
            activity.startActivity(intent)
        }

        private val statusTabs: MutableList<String> = mutableListOf(
            "待核销", "已核销"
        )
    }

    override val layoutResId: Int
        get() = R.layout.activity_settlement_order

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, color = R.color.colorWhite, view = flSettlementOrderBar)
    }


    override fun initView() {

        ivSettlementOrderBack.setOnClickListener { this.finish() }

        //tab&vp
        tabSettlementOrderStatus.apply {
            addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
                override fun onTabReselected(tab: TabLayout.Tab?) = Unit

                override fun onTabUnselected(tab: TabLayout.Tab?) {
                    tab?.customView = null
                }

                override fun onTabSelected(tab: TabLayout.Tab?) {
                    val text: TextView = TextView(context).apply {
                        setTextColor(ColorUtils.getColor(R.color.colorMain))
                        textSize = 16f
                        gravity = Gravity.CENTER
                        paint.isFakeBoldText = true
                    }
                    text.text = tab?.text
                    tab?.customView = text
                }
            })
        }.setupWithViewPager(vpSettlementOrderBody.apply {
            adapter = object : FragmentStatePagerAdapter(
                supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
            ) {

                override fun getItem(position: Int): Fragment =
                    SettlementOrderFragment.newInstance()

                override fun getCount(): Int = statusTabs.size

                override fun getPageTitle(position: Int): CharSequence? {
                    return statusTabs[position]
                }

                override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {}
            }
        })
    }

}